package com.ruicar.afs.cloud.afscase.externalinterface.controller;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.ruicar.afs.cloud.afscase.externalinterface.service.ExternalLoanAmountService;
import com.ruicar.afs.cloud.afscase.externalinterface.service.ExternalUsedCarService;
import com.ruicar.afs.cloud.afscase.externalinterface.vo.ExternalLoanAmountVo;
import com.ruicar.afs.cloud.afscase.externalinterface.vo.ExternalUsedCarVo;
import com.ruicar.afs.cloud.common.core.log.annotation.SysLog;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@AllArgsConstructor
@Api("审核任务")
@RequestMapping("/get")
public class ExternalAggregationController {
    private ExternalLoanAmountService amountService;
    private ExternalUsedCarService carService;

    @GetMapping("/loanhistory")
    @SysLog("历史贷款金额")
    public JSONArray loanhistory(@RequestParam String borrowerCertno, @RequestParam String coborrowerCertno) {
        List<ExternalLoanAmountVo> list = amountService.getLoanAmountHistory(borrowerCertno, coborrowerCertno);
        JSONArray array = new JSONArray();
        try {
            if (CollectionUtils.isNotEmpty(list)) {
                array.addAll(list);
            }
        } catch (Exception e) {
            log.info("接口异常原因：" + e.getMessage());
        }
        return array;
    }

    @GetMapping("/usedcarhistory")
    @SysLog("二手车历史存量vin查询")
    @Transactional
    public JSONArray usedcarhistory(@RequestParam String vin) {
        List<ExternalUsedCarVo> list = carService.getUsedCarhistory(vin);
        JSONArray jsonArray = new JSONArray();
        try {
            if (CollectionUtils.isNotEmpty(list)) {
                jsonArray.addAll(list);
            }
        } catch (Exception e) {
            log.info("接口异常原因：" + e.getMessage());
        }
        return jsonArray;
    }
}

